<?php
class CommonAction extends BaseAction{
	
	function _initialize() {
		if($_SESSION[self::GLOBAL_SESSION_USER_KEY] == null){
			//$this->redirect("Login/");
		}
		$this->assign("upload_dir", self::UPLOAD_DIR);
		$this->assign("upload_dir_access_uri", self::UPLOAD_DIR_ACCESS_URI);
	}
	
	// 图片上传
	protected function _upload($post, $imageName) {
		import("@.ORG.UploadFile");
		$upload = new UploadFile();
		//设置上传文件大小
		$upload->maxSize = 3292200;
		//设置上传文件类型
		$upload->allowExts = explode(',', 'jpg,gif,png,jpeg');
		//设置附件上传目录
		$upload->savePath = self::UPLOAD_DIR;
		//启用创建子目录
		$upload->autoSub = true;
		// 子目录创建方式 可以使用hash date
		$upload->subType = 'date';
		//设置需要生成缩略图，仅对图像文件有效
		$upload->thumb = false;
		// 设置引用图片类库包路径
		$upload->imageClassPath = '@.ORG.Image';
		//设置需要生成缩略图的文件后缀
		$upload->thumbPrefix = 'm_,s_';  //生产2张缩略图
		//设置缩略图最大宽度
		$upload->thumbMaxWidth = '400,100';
		//设置缩略图最大高度
		$upload->thumbMaxHeight = '400,100';
		//设置上传文件规则
		$upload->saveRule = 'uniqid';
		//删除原图
		$upload->thumbRemoveOrigin = true;
		if (!$upload->upload()) {
			//捕获上传异常
			$this->error($upload->getErrorMsg());
		} else {
			//取得成功上传的文件信息
			return $upload->getUploadFileInfo();
		}
	}
}